﻿using System.IO;
using System.Web;
using System.Web.UI;

namespace _5E.WebInfrastructure.UserControl
{
    public class ViewManager<T> where T : System.Web.UI.UserControl
    {
        private Page m_Page;

        public T LoadViewControl(string path)
        {
            m_Page = new Page();
            return (T)m_Page.LoadControl(path);
        }

        public string RenderView(T control)
        {
            var output = new StringWriter();
            m_Page.Controls.Add(control);
            HttpContext.Current.Server.Execute(m_Page, output, false);
            return output.ToString();
        }
    }
}
